home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-02-07 | 4.3 KB | 144 lines | [TEXT/MPS ] |
- (*
- NBPZoneList() -- Return a list of the zones on the local network.
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- pascal -w NBPZoneList.p
- link -m ENTRYPOINT -o HyperCommands -rt XFCN=2765 -sn Main=NBPZoneList ∂
- NBPZoneList.p.o "{MPW}"Libraries:interface.o "{MPW}"Libraries:Libraries:HyperXLib.o
-
- © Copyright 1990 by Apple Computer, Inc.
-
- Initial coding 6/90 by Harry R. Chesley.
- *)
-
- {$R-}
-
- {$S NBPZoneList } { Segment name must be the same as the command name. }
-
- unit DummyUnit;
-
- interface
-
- uses MemTypes, QuickDraw, OSIntf, ToolIntf, CTBUtils, FTIntf, CMIntf, TMIntf, CRMIntf, AppleTalk, HyperXCmd;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- implementation
-
- procedure NBPZoneList(paramPtr: XCmdPtr); forward;
-
- procedure EntryPoint(paramPtr: XCmdPtr);
-
- begin
- NBPZoneList(paramPtr);
- end;
-
- procedure NBPZoneList(paramPtr: XCmdPtr);
-
- {$I CTBUtil.inc}
-
- const kReturn = 13;
- kATPTimeOutVal = 3; { Re-try ATP SendRequest every 3 seconds. }
- kATPRetryCount = 5; { For five times. }
- kZonesSize = 578; { Size of buffer for zone names. }
- kGZLCall = $08000000; { GetZoneList indicator. }
- kZIPSocket = 6; { The Zone Information Protocol socket. }
- kMoreZones = $FF000000; { Mask to see if more zones to come. }
- kZoneCount = $0000FFFF; { Mask to count zones in buffer. }
-
- var dATPPBptr: ATPPBptr; { The parameter block for GetZoneList call. }
- dBDS: BDSElement; { The BDS for GetZoneList call. }
- dZones, dCurr: Ptr; { The data buffer for GetZoneList call. }
- dIndex, dCount, dNode, dNet: INTEGER;
- ignore: INTEGER;
- result: Handle;
- resultSize: longInt;
- p: Ptr;
-
- procedure Fail(errMsg: Str255); { set theResult and quit }
- begin
- { Get rid of any buffer space we allocated along the way. }
- if dATPPBptr <> nil then DisposPtr(Ptr(dATPPBptr));
- if dZones <> nil then DisposPtr(dZones);
- if result <> nil then DisposHandle(result);
- paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
- exit(NBPZoneList);
- end;
-
- begin
- { Init some important variables. }
- dATPPBptr := nil;
- dZones := nil;
- result := nil;
-
- { Check the parameter count. }
- if paramPtr^.paramCount > 0 then Fail('invalid parameter count');
-
- { Open AppleTalk. }
- FailOSErr(OpenDriver('.MPP', ignore));
- { Allocate buffers. }
- dATPPBptr := ATPPBptr(NewPtr(sizeOf(ATPParamBlock)));
- if dATPPBptr = nil then Fail('Out of memory');
- dZones := NewPtr(kZonesSize);
- if dZones = nil then Fail('Out of memory');
- { Fill in the request. }
- with dBDS do
- begin
- buffSize := kZonesSize;
- buffPtr := dZones;
- end;
- with dATPPBptr^ do
- begin
- atpFlags := 0;
- if GetNodeAddress(ignore, addrBlock.aNet) <> noErr then Fail('');
- if addrBlock.aNet = 0 then Fail('');
- addrBlock.aNode := GetBridgeAddress; { Get node of bridge. }
- addrBlock.aSocket := kZIPSocket; { The socket we want. }
- reqLength := 0;
- reqPointer := nil;
- bdsPointer := @dBDS;
- numOfBuffs := 1;
- timeOutVal := kATPTimeOutVal;
- retryCount := kATPRetryCount;
- end;
- { Prepare to cycle through the answers. }
- dIndex := 1;
- dCount := 0;
- result := NewHandle(0);
- if result = nil then Fail('Out of memory');
- resultSize := 0;
- repeat
- dATPPBptr^.userData := kGZLCall + dIndex; { Indicate GetZoneList request. }
- if PSendRequest(dATPPBptr, false) <> noErr then
- Fail('Network error');
- dCount := dCount + BAnd(dBDS.userBytes, kZoneCount); { Find out how many returned. }
- dCurr := dZones; { Put current pointer at start. }
- repeat { Get each zone. }
- resultSize := resultSize + dCurr^ + 1;
- SetHandleSize(result,resultSize);
- if MemError <> noErr then Fail('out of memory');
- BlockMove(pointer(ord4(dCurr)+1),pointer(ord4(result^)+resultSize-dCurr^-1),dCurr^);
- p := pointer(ord4(result^)+resultSize-1);
- p^ := kReturn;
- dCurr := pointer(ord4(dCurr) + dCurr^+1); { Bump up current pointer. }
- dIndex := dIndex + 1; { Increment which zone. }
- until dIndex > dCount;
- until (BAnd(dBDS.userBytes, kMoreZones) <> 0); { Keep going until none left. }
-
- { Get rid of the buffers. }
- DisposPtr(Ptr(dATPPBptr));
- DisposPtr(dZones);
-
- { Terminate and return the result. }
- if resultSize > 0 then
- begin
- p := pointer(ord4(result^)+resultSize-1);
- p^ := 0;
- paramPtr^.returnValue := result;
- end
- else DisposHandle(result);
- end;
-
- end.
-